<?php
	$this->load->view('includes/head.php');
	$date = standard_date(DATE_COOKIE,$task->date_created);
	date_default_timezone_set('GMT');
?>
<div class="container">
	<div class="row">
		<div class="col-sm-12">

			<h3><?php echo $task->title; ?> 
				<button class="pull-right btn btn-info">
					<a class="white" href="<?php echo site_url('tasks/edit/'.$task->url); ?>" title="Edit Task">Edit/Update Task <i class="fa fa-edit"></i></a>
				</button>
			</h3>

			<hr>
			<div class="row">
				<div class="col-sm-9 task_description">
					<?php echo $task->content; ?>
				</div>
				<div class="col-sm-3">
					
					<div class="panel panel-default">
						<div class="panel-heading">Information</div>
						<div class="panel-body">
							<p><strong>Owner:</strong> <?php echo $task->owner; ?><br>
							<small><em>Posted On: <?php echo mdate('%M %d, %Y',strtotime($task->date_created)); ?></em></small></p>
							<p><strong>Due Date:</strong> <small><em><?php echo mdate('%M %d, %Y',strtotime($task->date_due)); ?></em></small></p>
							<p><strong>Priority:  &nbsp;&nbsp;</strong> 
								<?php 
									switch ($task->priority) {
										case '1':
											echo '<span class="label label-default">Low</span>';
											break;
										case '2':
											echo '<span class="label label-primary">Normal</span>';
											break;
										case '3':
											echo '<span class="label label-danger">High</span>';
											break;
									}
								?>
							</p>
							<p><strong>Status: &nbsp;&nbsp;</strong> 
								<?php 
									switch ($task->status) {
										case 1:
											echo '<em>Not Started</em>';
											break;
										case 2:
											echo '<em>In Progress...</em>';
											break;
										case 3:
											echo '<em>Completed &nbsp;&nbsp;&nbsp;<span class="badge badge-success"><i class="fa fa-check white"></i></span></em>';
											break;
									}
								?>
							</p>
							
						</div>
					</div>


					<div class="panel panel-default">
						<div class="panel-heading">Assigned Roles</div>
						<div class="panel-body">
							<?php if (count($task->responsible) > 0 && is_array($task->responsible)): ?>
								<p style="margin-bottom:0;"><strong>Responsible: </strong></p>
								<p><small><em>
								<?php

									foreach ($task->responsible as $users_array) {
										$users = json_decode($users_array);
										foreach ($users as $user) {
											$name = $user->first_name . ' ' .$user->last_name;
											echo '<span class="names">'.$name.'</span>';
										}
									};
								?>
								</em></small>
								</p>
							<?php endif; ?>

							<?php if (count($task->accountable) > 0 && is_array($task->accountable)): ?>
								<p><strong>Accountable: </strong><small><em>
								<?php
									foreach ($task->accountable as $users_array) {
										$users = json_decode($users_array);
										foreach ($users as $user) {
											$name = $user->first_name . ' ' .$user->last_name;
											echo '<span class="names">'.$name.'</span>';
										}
									};
								?>
								</em></small>
								</p>
							<?php endif; ?>
							
							<?php if (count($task->consulted) > 0 && is_array($task->consulted)): ?>
								<p style="margin-bottom: 0;"><strong>Consulted: </strong></p>
								<p><small><em>
								<?php
									foreach ($task->consulted as $users_array) {
										$users = json_decode($users_array);
										foreach ($users as $user) {
											$name = $user->first_name . ' ' .$user->last_name;
											echo '<span class="names">'.$name.'</span>';
										}
									};
								?>
								</em></small>
								</p>
							<?php endif; ?>

							
							<?php if ( count($task->informed) > 0 && is_array($task->informed) ): ?>
								<p style="margin-bottom: 0;"><strong>Informed: </strong></p>
								<p><small><em>
								<?php
									foreach ($task->informed as $users_array) {
										$users = json_decode($users_array);
										foreach ($users as $user) {
											$name = $user->first_name . ' ' .$user->last_name;
											echo '<span class="names">'.$name.'</span>';
										}
									};
								?>
								</em></small>
								</p>
							<?php endif ?>

							
						</div>
					</div>
					
				</div>
			</div>
		</div>


	    <div class="col-sm-12">
	      <h3>Comments</h3>
	      <hr class="comment">



	      






		<div id="comment-div">
		<?php
			if(is_array($comments) && count($comments) > 0){

				foreach ($comments as $comment) {

					$date = $comment->timestamp;
					$name = $comment->name;
					echo<<<COM
						<div class="comment-container">
							<p><strong>$name</strong> <small><em>- Posted <span class="time_passed" data-timestamp="$date"></span> </small></em></p>
							<div>
								$comment->comment
							</div>
						<hr>
						</div>
COM;
				}
			}else{
				echo '<p id="no-comments"><em>No comments have been posted. Please <a href="#" id="show-textarea">Click Here</a> to a comment.</em></p>';
			}
		?>
		</div>





	</div>

		
	    <div class="col-sm-12 top_3 bottom-margin" id="add_comment_form">
		    <?php echo form_open('manage/add_comment',array('role' => 'form' )); ?>
		    	<input type="hidden" name="user_id" value="<?php echo $user_id; ?>" />
		    	<input type="hidden" name="task_id" value="<?php echo $task->id; ?>" />
		    	<p><textarea name="comment" id="textarea_comment" class="form-control" rows="5"></textarea></p>
		    	<p><button type="submit" id="textarea_submit" disabled class="btn btn-info pull-right">Add Comment</button></p>
		    <?php echo form_close(); ?>
		</div>






</div>
